/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaConsultas.java
 *
 * Created on 04/06/2011, 12:10:24
 */

package campeonatobrasuka;

import campeonatobrasuka.TableModels.TecnicoTableModel;
import campeonatobrasuka.TableModels.ArbitroTableModel;
import campeonatobrasuka.TableModels.ClubeTableModel;
import campeonatobrasuka.TableModels.EstadioTableModel;
import campeonatobrasuka.TableModels.PartidaTableModel;
import campeonatobrasuka.TableModels.PresidenteTableModel;
import campeonatobrasuka.TableModels.JogadorTableModel;
import Persistencia.modelos.Time;       
import javax.swing.JOptionPane;


/**
 *
 * @author Jaqueline Ishiyama
 */
public class TelaConsultas extends javax.swing.JPanel {
DefaultFormatter form = new DefaultFormatter();

String [] colunas;
    /** Creates new form TelaConsultas */
    public TelaConsultas() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmbConsulta = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        txtConsultaNome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        btnConsultar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jButton3 = new javax.swing.JButton();
        scrlPane = new javax.swing.JScrollPane();
        tblConsultas = new javax.swing.JTable();

        setName("Form"); // NOI18N

        cmbConsulta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Clube", "Jogador", "Estádio", "Técnico", "Presidente", "Árbitro", "Partida" }));
        cmbConsulta.setSelectedIndex(-1);
        cmbConsulta.setName("cmbConsulta"); // NOI18N
        cmbConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbConsultaActionPerformed(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(campeonatobrasuka.CampeonatoBrasukaApp.class).getContext().getResourceMap(TelaConsultas.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtConsultaNome.setName("txtConsultaNome"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        btnConsultar.setText(resourceMap.getString("btnConsultar.text")); // NOI18N
        btnConsultar.setName("btnConsultar"); // NOI18N
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setEnabled(false);
        jButton1.setName("jButton1"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        scrlPane.setName("pnlTable"); // NOI18N

        tblConsultas.setName("tblConsultas"); // NOI18N
        scrlPane.setViewportView(tblConsultas);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cmbConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnConsultar))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtConsultaNome, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton3)))
                        .addGap(43, 43, 43))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scrlPane, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnConsultar))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtConsultaNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrlPane, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        int selectedIndex = cmbConsulta.getSelectedIndex();
        if (selectedIndex==-1)
            JOptionPane.showMessageDialog(this,"Você deve escolher um tipo para a consulta");
        
         if (selectedIndex==0){
            tblConsultas.setModel(new ClubeTableModel());                        
        } else if (selectedIndex==1){
            tblConsultas.setModel(new TecnicoTableModel());
        } else if (selectedIndex==2){
            tblConsultas.setModel(new ArbitroTableModel());
        } else if (selectedIndex==3){
            tblConsultas.setModel(new PresidenteTableModel());
        } else if (selectedIndex==4){
            tblConsultas.setModel(new JogadorTableModel());
        } else {
            tblConsultas.setModel(new PartidaTableModel());
        } 
        scrlPane.setViewportView(tblConsultas);
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        // TODO add your handling code here:
        //BOTÃO ALTERAR REGISTRO
        /*AlterarComponentes novo = new AlterarComponentes();
        novo.setVisible(true);
        String tipo = null;

        if (cmbConsulta.getSelectedItem().equals("Clube")) {
        tipo ="Clube";
        }
        else if (cmbConsulta.getSelectedItem().equals("Jogador")) {
        tipo = "Jogador";
        }
        else if (cmbConsulta.getSelectedItem().equals("Técnico")) {
         tipo = "Técnico";
        }
         else if (cmbConsulta.getSelectedItem().equals("Árbitro")) {
          tipo = "Árbitro";
         }
        else if (cmbConsulta.getSelectedItem().equals("Presidente")){
         tipo = "Presidente";
        }
        else if (cmbConsulta.getSelectedItem().equals("Estádio")){
         tipo = "Estádio";
        }
        else if (cmbConsulta.getSelectedItem().equals("Partida")){
         tipo = "Partida";
        }

        novo.setTipoAlteracao(tipo);
*/        
    }//GEN-LAST:event_jButton3MouseClicked

    private void cmbConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbConsultaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cmbConsultaActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        ClubeTableModel ctm = ((ClubeTableModel) tblConsultas.getModel());
        Time time = (Time) ctm.getObjectAt(tblConsultas.getSelectedRow());        
        
        Clube clube = new Clube(time);        
        scrlPane.setViewportView(clube);        
        clube.setVisible(true);
        tblConsultas.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConsultar;
    private javax.swing.JComboBox cmbConsulta;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JScrollPane scrlPane;
    private javax.swing.JTable tblConsultas;
    private javax.swing.JTextField txtConsultaNome;
    // End of variables declaration//GEN-END:variables

}
